<?php
class VideoExterno {
	var $url;
	var $id;
	var $service;
	var $width;
	var $heigth;
	
	function VideoExterno($url) {
		// Largura e tamanho padrão para os vídeos
		$this->width = 420;
		$this->heigth = 325;

		$this->url = $url;
		$res = preg_match_all("/.+?(archive|youtube|vimeo|videolog|youtu)\.(com|org|be|tv).+/", $url, $out);
		$this->service = $out[1][0];
		switch ($this->service) {
			case "youtube":
				parse_str( parse_url( $url, PHP_URL_QUERY ) );
				$this->id = $v;
				break;
			case "vimeo":
				preg_match_all("/.\/([0-9]+)[&\/]?/", $url, $id);
				$this->id = $id[1][0];
				break;
			case "archive":
				preg_match_all("/.+org\/details\/(.+)/", $url, $id);
				$this->id = $id[1][0];
				break;
			case "videolog":
				preg_match_all("/video\.php\?id=([0-9]+)/", $url, $id);
				$this->id = $id[1][0];
				break;
		}
	}

	function geraEmbed () {
		switch ($this->service) {
			case 'vimeo':
				return '<iframe src="http://player.vimeo.com/video/'.$this->id.'?byline=0&amp;portrait=0" width="'.$this->width.'" height="'.$this->heigth.'" frameborder="0"></iframe>';
				break;
			case 'youtube':
				return '<object width="'.$this->width.'" height="'.$this->heigth.'"><param name="movie" value="http://www.youtube.com/v/'.$this->id.'?fs=1&amp;hl=pt_BR"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/'.$this->id.'?fs=1&amp;hl=pt_BR" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="'.$this->width.'" height="'.$this->heigth.'"></embed></object>';
				break;
			case 'google';
				return '<embed id=VideoPlayback src=http://video.google.com/googleplayer.swf?docid=-570340003958234038&hl=pt-BR&fs=true style=width:400px;height:326px allowFullScreen=true allowScriptAccess=always type=application/x-shockwave-flash> </embed>';
				break;
			case 'archive':
				return "<object width=\"".$this->width."\" height=\"".$this->heigth."\" classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\"><param value=\"true\" name=\"allowfullscreen\"/><param value=\"always\" name=\"allowscriptaccess\"/><param value=\"high\" name=\"quality\"/><param value=\"true\" name=\"cachebusting\"/><param value=\"#000000\" name=\"bgcolor\"/><param name=\"movie\" value=\"http://www.archive.org/flow/flowplayer.commercial-3.2.1.swf\" /><param value=\"config={'key':'#\$aa4baff94a9bdcafce8','playlist':['format=Thumbnail?.jpg',{'autoPlay':false,'url':'Sudenly_512kb.mp4'}],'clip':{'autoPlay':true,'baseUrl':'http://www.archive.org/download/".$this->id."/','scaling':'fit','provider':'h264streaming'},'canvas':{'backgroundColor':'#000000','backgroundGradient':'none'},'plugins':{'controls':{'playlist':false,'fullscreen':true,'height':26,'backgroundColor':'#000000','autoHide':{'fullscreenOnly':true}},'h264streaming':{'url':'http://www.archive.org/flow/flowplayer.pseudostreaming-3.2.1.swf'}},'contextMenu':[{},'-','Flowplayer v3.2.1']}\" name=\"flashvars\"/><embed src=\"http://www.archive.org/flow/flowplayer.commercial-3.2.1.swf\" type=\"application/x-shockwave-flash\" width=\"".$this->width."\" height=\"".$this->heigth."\" allowfullscreen=\"true\" allowscriptaccess=\"always\" cachebusting=\"true\" bgcolor=\"#000000\" quality=\"high\" flashvars=\"config={'key':'#\$aa4baff94a9bdcafce8','playlist':['format=Thumbnail?.jpg',{'autoPlay':false,'url':'Sudenly_512kb.mp4'}],'clip':{'autoPlay':true,'baseUrl':'http://www.archive.org/download/".$this->id."/','scaling':'fit','provider':'h264streaming'},'canvas':{'backgroundColor':'#000000','backgroundGradient':'none'},'plugins':{'controls':{'playlist':false,'fullscreen':true,'height':26,'backgroundColor':'#000000','autoHide':{'fullscreenOnly':true}},'h264streaming':{'url':'http://www.archive.org/flow/flowplayer.pseudostreaming-3.2.1.swf'}},'contextMenu':[{},'-','Flowplayer v3.2.1']}\"> </embed></object>";
				break;
			case 'videolog':
				return "<object id='playerFlash' classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' width='".$this->width."' height='".$this->heigth."'><param name='movie' value='http://www.videolog.tv/ajax/codigoPlayer.php?id_video=".$this->id."&relacionados=S&default=S&lang=PT_BR&cor_fundo=FFFFFF&cor_titulo=777777&hd=S&swf=1&width=".$this->width."&height=".$this->heigth."' /><param name='flashvars' value='id_video=".$this->id."' /><param name='allowScriptAccess' value='always' /><param name='allowFullScreen' value='true' /><param name='wmode' value='opaque' /><embed src=\"http://www.videolog.tv/ajax/codigoPlayer.php?id_video=".$this->id."&relacionados=S&default=S&lang=PT_BR&cor_fundo=FFFFFF&cor_titulo=777777&hd=S&swf=1&width=".$this->width."&height=".$this->heigth."\" type=\"application/x-shockwave-flash\" allowscriptaccess=\"always\" allowfullscreen=\"true\" width=\"".$this->width."\" height=\"".$this->heigth."\"></embed></object>";
				break;
		}
	}
}
?>